{% load jrc_shared %}

{% for week in month %}

    {% if week.monday != 0 %}
        {% for tr in week.get_futures_tracks_for_monday %}
            <tr class="row1" style="padding-top: 1px; padding-bottom: 1px;">
                {% if forloop.last %}
                    {% include "tracking/_futures_tr_total.html" with tr=tr %}
                {% else %}
                    {% include "tracking/_futures_tr.html" with tr=tr %}
                {% endif %}
            </tr>
        {% empty %}
            <tr class="row1">
                
                <td style="color: darkgray;" nowrap>{{ week.get_date_for_monday|date:"d" }}, Mon</td>
                <td colspan="14" style="color: darkgray;">No tracks</td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}

    {% if week.tuesday != 0 %}
        {% for tr in week.get_futures_tracks_for_tuesday %}
            <tr class="row2">
                {% if forloop.last %}
                    {% include "tracking/_futures_tr_total.html" with tr=tr %}
                {% else %}
                    {% include "tracking/_futures_tr.html" with tr=tr %}
                {% endif %}
            </tr>
        {% empty %}
            <tr class="row2">

                <td style="color: darkgray;">{{ week.get_date_for_tuesday|date:"d" }}, Tue</td>
                <td colspan="14" style="color: darkgray;">No tracks</td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}

    {% if week.wednesday != 0 %}
        {% for tr in week.get_futures_tracks_for_wednesday %}
            <tr class="row1">
                {% if forloop.last %}
                    {% include "tracking/_futures_tr_total.html" with tr=tr %}
                {% else %}
                    {% include "tracking/_futures_tr.html" with tr=tr %}
                {% endif %}
            </tr>
        {% empty %}
            <tr class="row1">

                <td style="color: darkgray;" nowrap>{{ week.get_date_for_wednesday|date:"d" }}, Wed</td>
                <td colspan="14" style="color: darkgray;">No tracks</td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}

    {% if week.thursday != 0 %}
        {% for tr in week.get_futures_tracks_for_thursday %}
            <tr class="row2">
                {% if forloop.last %}
                    {% include "tracking/_futures_tr_total.html" with tr=tr %}
                {% else %}
                    {% include "tracking/_futures_tr.html" with tr=tr %}
                {% endif %}
            </tr>
        {% empty %}
            <tr class="row2">

                <td style="color: darkgray;">{{ week.get_date_for_thursday|date:"d" }}, Thu</td>
                <td colspan="14" style="color: darkgray;">No tracks</td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}

    {% if week.friday != 0 %}
        {% for tr in week.get_futures_tracks_for_friday %}
            <tr class="row1">
                {% if forloop.last %}
                    {% include "tracking/_futures_tr_total.html" with tr=tr %}
                {% else %}
                    {% include "tracking/_futures_tr.html" with tr=tr %}
                {% endif %}
            </tr>
        {% empty %}
            <tr class="row1">

                <td style="color: darkgray;">{{ week.get_date_for_friday|date:"d" }}, Fri</td>
                <td colspan="14" style="color: darkgray;">No tracks</td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}

    {% if week.saturday != 0 %}
        {% for tr in week.get_futures_tracks_for_saturday %}
            <tr class="row2">
                {% if forloop.last %}
                    {% include "tracking/_futures_tr_total.html" with tr=tr %}
                {% else %}
                    {% include "tracking/_futures_tr.html" with tr=tr %}
                {% endif %}
            </tr>
        {% empty %}
            <tr class="row2">
                <td style="color: red;">{{ week.get_date_for_saturday|date:"d" }}, Sat</td>
                <td colspan="14"></td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}

    {% if week.sunday != 0 %}
        {% for tr in week.get_futures_tracks_for_sunday %}
            <tr class="row1">
                {% if forloop.last %}
                    {% include "tracking/_futures_tr_total.html" with tr=tr %}
                {% else %}
                    {% include "tracking/_futures_tr.html" with tr=tr %}
                {% endif %}
            </tr>
        {% empty %}
            <tr class="row1">
                <td style="color: red;">{{ week.get_date_for_sunday|date:"d" }}, Sun</td>
                <td colspan="14"></td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}

    <tr>
        <td colspan="18" style="border-top: solid 1px black;">&nbsp;</td>
    </tr>

{% endfor %}

    <tr style="font-weight: bold;">
        <td>Totals</td>
        <td>&nbsp;</td>
        <td>{{ month_stats.contracts_qnt_total }}</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>{{ month_stats.points_total|jrc_intformat }}</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>{{ month_stats.profit_losses_total|jrc_intformat }}</td>
        <td>{{ month_stats.profit_losses_fees_total|jrc_intformat }}</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>{{ month_stats.number_of_trades_total|jrc_intformat }}</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>


<script type="text/javascript">

    // Format data to dipslay daily P/L chart
    {% for p in month_stats.profit_losses_daily %}
        {% if p != 0 %}
            gArProfitLossesDaily[gArProfitLossesDaily.length] = ['{{ forloop.counter }}', -1, {{ p }}];
        {% endif %}
    {% endfor %}

     // Format data to display percentiles chart
    {% for p in month_stats.percentiles %}
        gArPercentiles[gArPercentiles.length] = ['{{ forloop.counter }}',{{ p.1 }}];
    {% endfor %}
    
    gMarketsTotalsMin = {{ month_stats.markets_totals_min }};
    gMarketsTotalsMax = {{ month_stats.markets_totals_max }};
    gArMarketsNamesAndTotals = [
        ['Markets', ''], 
        {% for m, v in month_stats.markets_totals.iteritems %}
            ["{{ m }}", {{ v }}], 
        {% endfor %}
    ];

    {% for m, v in month_stats.markets_totals.iteritems %}
        gArMarketsNames[gArMarketsNames.length] = "{{ m }}";
        gArMarketsTotals[gArMarketsTotals.length] = {{ v }};
    {% endfor %}

</script>
